feat: Add pretty print toggle for request and response bodies in network details#39682
feat: Add pretty print toggle for request and response bodies in network details#39682cpAdm wants to merge 3 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a user-facing “Pretty print” toggle in Trace Viewer’s Network details to switch between raw and formatted request/response bodies, with persisted settings and an error indicator when formatting fails.
Changes:
- Introduces pretty-print toggles for request payload (header button) and response body (bottom toolbar) with localStorage-backed persistence.
- Refactors the existing “error dot” indicator into a reusable
ToolbarButtonerrorBadgeprop and applies it to the UI mode output toggle. - Updates UI-mode tests to assert copying uses the original (unformatted) request body and validates the new request-body toggle behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/playwright-test/ui-mode-test-network-tab.spec.ts | Extends request-body formatting tests and adjusts copy-request expectations to use raw body. |
| packages/web/src/components/toolbarButton.tsx | Adds errorBadge support to show an error indicator on toolbar buttons. |
| packages/web/src/components/toolbarButton.css | Styles the new toolbar-button error badge and makes buttons positioning-relative. |
| packages/web/src/components/toolbar.css | Updates shadow styling selector to exclude .no-shadow toolbars via :not(...). |
| packages/trace-viewer/src/ui/uiModeView.tsx | Switches output error indicator to the new ToolbarButton errorBadge prop. |
| packages/trace-viewer/src/ui/networkResourceDetails.tsx | Adds pretty-print toggles for request/response bodies and centralizes formatting logic in useFormattedBody. |
| packages/trace-viewer/src/ui/networkResourceDetails.css | Adds response bottom toolbar styling and response-body sizing rule. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Adds a user-controlled pretty-print toggle for request/response bodies in the Trace Viewer Network details pane, including persistent settings and surfaced formatting errors, to improve readability of JSON/XML bodies.
Changes:
- Introduces “Pretty print” toggle UI for request bodies (section title) and response bodies (bottom toolbar), with persisted defaults via
useSetting. - Extracts/extends a reusable
ToolbarButtonerror badge indicator and updates toolbar shadow styling. - Updates UI mode network tab tests to cover toggling behavior, response pretty-printing, and formatting error badge behavior; adjusts copy-as-Playwright expectation to use the original (unformatted) request body.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/playwright-test/ui-mode-test-network-tab.spec.ts | Adds/updates UI mode coverage for pretty-print toggles, response formatting, error badge behavior, and copy semantics. |
| packages/web/src/components/toolbarButton.tsx | Extends ToolbarButton with an optional error badge indicator and associated ARIA wiring. |
| packages/web/src/components/toolbarButton.css | Styles the new error badge and enables absolute positioning within the button. |
| packages/web/src/components/toolbar.css | Refines shadow pseudo-element application to exclude no-shadow toolbars. |
| packages/trace-viewer/src/ui/uiModeView.tsx | Switches output error indicator to use the shared ToolbarButton error badge. |
| packages/trace-viewer/src/ui/networkResourceDetails.tsx | Adds formatting toggle UI + persisted settings; centralizes formatting with error reporting; ensures copy uses original body. |
| packages/trace-viewer/src/ui/networkResourceDetails.css | Styles response toolbar/container layout for the new bottom toolbar. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Chris <57954026+cpAdm@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a “Pretty print” toggle for request/response bodies in the trace viewer’s Network details, including error indication when formatting fails, and persists formatting preferences.
Changes:
- Add UI toggles for formatting request/response bodies and persist the setting via
useSetting. - Introduce
errorBadgesupport inToolbarButtonand use it to surface formatting failures. - Update UI mode network tab tests to cover pretty printing, toggling, and error-badge behavior; adjust copy-request expectations to use the original body.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/playwright-test/ui-mode-test-network-tab.spec.ts | Extends UI mode network tests to verify pretty print toggles and formatting failure indicator; updates copy behavior assertions. |
| packages/web/src/components/toolbarButton.tsx | Adds errorBadge rendering and ARIA wiring for toolbar buttons. |
| packages/web/src/components/toolbarButton.css | Supports error badge positioning by making buttons position: relative and styling the badge. |
| packages/web/src/components/toolbar.css | Simplifies shadow styling by gating the :after shadow on .no-shadow. |
| packages/trace-viewer/src/ui/uiModeView.tsx | Replaces custom error-dot markup with ToolbarButton.errorBadge. |
| packages/trace-viewer/src/ui/networkResourceDetails.tsx | Implements formatted/unformatted body toggles for request/response, adds formatting error handling, and updates body formatting logic. |
| packages/trace-viewer/src/ui/networkResourceDetails.css | Adds layout/styling for the response toolbar and response body container. |
| server.setRoute('/response-json-good', (_, res) => res.setHeader('Content-Type', 'application/json').end('{"ok":true,"items":[1,2]}')); | ||
| server.setRoute('/response-json-bad', (_, res) => res.setHeader('Content-Type', 'application/json').end('{"ok":true,,}')); |
| <> | ||
| <div style={{ margin: 'auto' }}></div> | ||
| <FormatToggleButton toggled={showFormatted} error={formatResult.error} onToggle={() => setShowFormatted(!showFormatted)} /> | ||
| </> |
| <Toolbar noShadow={true} noMinHeight={true} className='network-response-toolbar'> | ||
| <div style={{ margin: 'auto' }}></div> |
Test results for "MCP"1 failed 5506 passed, 343 skipped Merge workflow run. |
Test results for "tests 1"3 flaky38823 passed, 845 skipped Merge workflow run. |
Follow up on #39405,
uiModeView.tsx(extracted toToolbarButton)Loading...which in most cases just causing flickering anyway (since most bodies are fetched very quickly)<Empty>, but to line up with e.g. Chrome Devtools, we now just show an empty editor to avoid confusionIf formatting fails:

Example test to showcase this new feature
If we want, we can extract
useFormattedBodyand its helper functions to a separate file as suggested here?Closes: #37963